﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TextEditor.TextDocument.Action
{
    public class A_CtrlTabToInput : A_Action
    {
        public A_CtrlTabToInput()
        {
            this.HotKey = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Tab;
        }

        public override string ActionName()
        {
            return "onkeyctrltab";
        }

        public override bool isEnable()
        {
            return base.myOwnerDocument.CanModify();
        }

        public override bool Execute()
        {
            if (this.OwnerDocument.Content.CurrentElement != null)
            {
                ZYTextElement element = this.OwnerDocument.Content.CurrentElement;
                if (element != null)
                {
                    int index = this.OwnerDocument.Elements.IndexOf(element);
                    if (index < this.OwnerDocument.Elements.Count)
                    {
                        index += 1;
                        for (int i = index; i < this.OwnerDocument.Elements.Count; i++)
                        {
                            ZYTextElement moveToElement = (ZYTextElement)this.OwnerDocument.Elements[i];
                            if (moveToElement is ZYTextInput)
                            {
                                base.OwnerDocument.Content.AutoClearSelection = true;
                                base.OwnerDocument.Content.MoveSelectStart(i + 1);
                                this.OwnerDocument.UpdateCaret();
                                break;
                            }
                        }
                    }
                }
            }
            return true;
        }
    }
}
